<template>
  <div id="app">
    <header class="head">
      <a class="back tl" href="javascript:history.back(-1)">
        <i class="el-icon-arrow-left"></i>
      </a>
      <a href="javascript:;" class="tc">
        <small class="font_18 co_f">快检管理</small>
      </a>
    </header>
    <main>
      <div class="seachfrom">
        <div class="seachbox">
          <el-input placeholder="请输入样品名称、企业名称或者判定结果" v-model="seachtext">
            <el-button slot="append" icon="search" @click="seach()"></el-button>
          </el-input>
        </div>
      </div>
      <div v-loading='loading'>
        <v-loadmore :top-method="loadTop" :bottom-method="loadBottom" :bottom-all-loaded="allLoaded" :auto-fill="false" ref="loadmore">
          <ul class="datalist">
            <li v-for="item in listData" :key='item.unid'>
              <a @click="KJSJdetail(item)">
                <div class="items-img">
                  <img src="../../assets/iconimg.png" />
                </div>
                <div class="items-text">
                  <p>检测项目:{{item.detectionItem}}</p>
                  <p>样品名称：{{item.sampleName}}</p>
                  <p>企业名称：{{item.enterpriseName}}</p>
                  <p>操作人:{{item.personName}}</p>
                  <p>结果判定：{{item.detectionResult}}</p>
                </div>
              </a>
            </li>
          </ul>
        </v-loadmore>
        <div class="none_data" v-show="nonedata">
          <img src="../../img/tip.png">
        </div>
      </div>
    </main>
  </div>
</template>

<script>
  import {
    Loadmore
  } from 'mint-ui';
  import {
    DetectionHiostoryData
  } from '../../api/api';
  export default {
    components: {
      'v-loadmore': Loadmore,
    },
    data() {
      return {
        loading: true,
        nonedata: false,
        PageSize: 10,
        CurrentPage: 1,
        CriteriaList: [],
        listData: [],
        seachtext: '',
        select: '',
        allLoaded: false,
        scrollMode: "auto"
      };
    },
    watch: {
        listData(val) {
            if (val) {
                this.loading = false;
            }
        },
    },
    methods: {
      KJSJdetail: function(item) {
        this.$router.push({
          name: 'KJSJdetail'
        })
        sessionStorage.setItem('KJSJdetail', JSON.stringify({
          content: item,
        }));
      },
      loadTop: function() { //组件提供的下拉触发方法  
        //下拉刷新
        if (this.CurrentPage >= 0) {
          this.CurrentPage = 1;
          this.listData = [];
          this.getData();
        } else {
          this.listData = [];
          this.getData();
        }
        this.$refs.loadmore.onTopLoaded();
      },
      loadBottom: function() {
        // 上拉加载  
        this.CurrentPage += 1;
        this.getData();
        this.$refs.loadmore.onBottomLoaded();
      },
      //搜索
      seach: function() {
        this.listData = [];
        this.CurrentPage = 1;
        this.CriteriaList[0] = {
          Name: 'SampleName',
          Value: '%' + this.seachtext + '%',
          Operate: 'Like',
          DataType: null,
          EndSuffix: '',
          Suffix: null
        };
        this.CriteriaList[1] = {
          Name: 'EnterpriseName',
          Value: '%' + this.seachtext + '%',
          Operate: 'Like',
          DataType: null,
          EndSuffix: '',
          Suffix: null
        };
        this.CriteriaList[2] = {
          Name: 'DetectionResult',
          Value: '%' + this.seachtext + '%',
          Operate: 'Like',
          DataType: null,
          EndSuffix: '',
          Suffix: null
        };
        this.getData();
      },
      //数据加载方法
      getData() {
        let CurrentPageNum = this.CurrentPage
        //定义需要传给通讯的参数：QueryData{"PageSize":10,"CurrentPage":1,"Query":{"CriteriaList":[]}}和userunid    
        let varQueryData = {
          PageSize: this.PageSize,
          CurrentPage: this.CurrentPage,
          Query: {
            CriteriaList: [],
            SubQueryList: []
          }
        }
        if (this.CriteriaList.length !== 0) {
          let SubQueryList = [{
            CriteriaList: this.CriteriaList,
            Relation: 'or'
          }]
          varQueryData.Query.SubQueryList = SubQueryList;
        }
        let options = {
          params: {
            QueryData: JSON.stringify(varQueryData),
            EnterpriseUnid: JSON.parse(localStorage.getItem('auth')).enterpriseUnid,
          }
        }
        //调取接口
        DetectionHiostoryData(options).then((res) => {
          if (res.success === true) {
            this.listData = this.listData.concat(res.data.data);
            if (res.data.data.length > 0) {
              this.nonedata = false
            } else {
              if (CurrentPageNum == 1) {
                this.nonedata = true
              } else {
                this.nonedata = false
              }
            }
          }
        })
      }
    },
    //页面加载时候
    mounted() {
      this.getData();
    }
  
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style lang="scss" scoped>
  
</style>
